package com.estudy.controller;

import com.estudy.domain.Employee;
import com.estudy.exception.CustomerException;
import com.estudy.service.EmployeeService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Employee)表控制层
 *
 * @author zqx
 * @since 2024-08-26 23:36:49
 */
@RestController
@RequestMapping("/employee")
public class EmployeeController {
    /**
     * 服务对象
     */
    @Resource
    private EmployeeService employeeService;

    /**
     * 查询所有数据
     *
     * @return 实例对象集合
     */
    @GetMapping("/all")
    public List<Employee> queryAll() {
        return this.employeeService.queryAll();
    }
    
    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/get/{id}")
    public Employee queryById(@PathVariable("id") Integer id) {
        return this.employeeService.queryById(id);
    }

    /**
     * 增加数据
     *
     * @param employee 新增实体
     * @return 影响行数
     */
    @PostMapping("/insert")
    public Integer insert(@RequestBody Employee employee) {
        return this.employeeService.insert(employee);
    }

    /**
     * 修改数据
     *
     * @param employee 实体
     * @return 修改是否成功
     */
    @PutMapping("/update")
    public Integer update (@RequestBody Employee employee) {
        return this.employeeService.update(employee);
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("/delete/{id}")
    public Integer deleteById (@PathVariable("id") Integer id) {
        return this.employeeService.deleteById(id);
    }

    @GetMapping("/hello")
    public String hello() {
        throw new CustomerException(9999, "错误1");
    }
}


